package com.mitac.mcd.cs.mobiletracking.socketserver.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.text.SimpleDateFormat;

import net.sf.json.JSONObject;

import com.mitac.mcd.cs.mobiletracking.socketserver.MobileServer;

public class testSendNotification {

	private static final String ADDRESS = "192.168.1.104";
	private static final int PORT = 9020;
	private static SocketAddress socketaddress = new InetSocketAddress(ADDRESS,PORT);
	public static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss yyyy/MM/dd");
	
	public static void main(String args[]) throws IOException, InterruptedException{
		Socket socket = null;
        
        String e = "{'cmd':'killcmd','uuidclients':[{'uid':'34159e466ca2'},{'uid':'38e7d822ced5'},{'uid':'38e7d822eeee'}], 'useridclients':[{'userid':169},{'userid':163},{'userid':1644}]}";
		//String e = "{\"cmd\":\"notificationcmd\", \"type\":1, \"newest\":true,\"clients\":[{\"uid\":\"7c6d6203b015\", \"badge\":5 },{\"uid\":\"starkdeviceuuid\", \"badge\":5 }]}";
        try {
	        	boolean _run = true;
	    		socket = new Socket();
	    		socket.connect(socketaddress,50*1000);
	    		OutputStream Os = null;
				PrintStream PS = null;
				if (!socket.isClosed()){
	                Os = socket.getOutputStream();
	                PS = new PrintStream(Os);
	    		}
	    		PS.println(e);
	    		BusinessUtil.aLogger.info("Upload Client OK");
	    		/*InputStream Is = null;
	    		BufferedReader inBr = null;
	    		String str = null;
	    		while(_run){
	    			BusinessUtil.aLogger.info("Begin waiting...");
	    			Is = socket.getInputStream();
	    			inBr = new BufferedReader(new InputStreamReader(Is,"UTF-8"));
	    			str = inBr.readLine();
	    			BusinessUtil.aLogger.info("Server said:"+str);
	    			_run = false;
	    		}*/
	    		
	    		PS.close();
	            Os.close();
	            socket.close();
	            System.exit(0);
        } catch (Exception e1) {
        	socket.close();
        	e1.printStackTrace();
			BusinessUtil.aLogger.info("连接初始化失败....");
			System.exit(1);
		}
        
	}
	
}
